
package jfireeagle.examples.swing;

import javax.swing.JTextField;

import java.util.*;
import java.text.*;


public class DateTimeField extends JTextField
{
	private static final String PATTERN = "yyyy/MM/dd HH:mm:ss";
	
	public DateTimeField()
	{
		this(Calendar.getInstance());
	}
	
	public DateTimeField(Calendar c)
	{
		super();
		
		SimpleDateFormat fmt = new SimpleDateFormat(PATTERN);
		
		this.setText(fmt.format(c.getTime()));
		
	}
	
	public Date getDate()
	{
		Date d = null;
		
		if (this.getText() != null)
		{
			SimpleDateFormat fmt = new SimpleDateFormat(PATTERN);
			try
			{
				d = fmt.parse(this.getText());
			}
			catch (Exception ex)
			{
				d = null;
			}
		}
		
		return d;
	}
}
